package com.flute.framework.index.fieldbuilder;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class ScoreField {
	public static final int DEFAULT_SCORE = 0;
	public static final String ACTIVITY_SCORE = "activity";

	public String text;
	private List<String> strings;
	private HashMap<String, List<SorterScore>> scores;

	public ScoreField() {
		this.strings = new ArrayList<String>();
		this.scores = new HashMap<String, List<SorterScore>>();
	}

	public void addString(String string) {
		this.strings.add(string);
	}

	public String getText() {
		return text;
	}

	public void setText(String text) {
		this.text = text;
	}

	public int size() {
		return strings.size();
	}

	public List<String> getStrings() {
		return strings;
	}

	public void addScore(String token, int name, float score) {
		if (!scores.containsKey(token)) {
			scores.put(token, new ArrayList<SorterScore>());
		}

		scores.get(token).add(new SorterScore(name, score));
	}

	public void addScore(String token, SorterScore score) {
		if (!scores.containsKey(token)) {
			scores.put(token, new ArrayList<SorterScore>());
		}

		scores.get(token).add(score);
	}

	public String getString(int index) {
		if (index >= 0 && index < strings.size()) {
			return strings.get(index);
		}

		return "";
	}

	public ScoreMap getScores(String token) {
		List<SorterScore> list = scores.get(token);
		ScoreMap map = new ScoreMap();
		if (list != null) {
			for (SorterScore ss : list) {
				map.addScore(ss.getSorterName(), ss.getScore());
			}
		}
		return map;
	}

	public void updateScore(String string, int scoreName, float score) {
		List<SorterScore> list = scores.get(string);
		if (list != null) {
			for (int i = 0; i < list.size(); i++) {
				if (list.get(i).getSorterName() == scoreName) {
					list.get(i).setScore(score);
				}
			}
		}
	}
}
